package com.ruoyi.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.user.domain.TbOwner;
import com.ruoyi.user.mapper.TbOwnerMapper;
import com.ruoyi.user.service.ITbOwnerService;

/**
 * 业主管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@Service
public class TbOwnerServiceImpl implements ITbOwnerService 
{
    @Autowired
    private TbOwnerMapper tbOwnerMapper;

    /**
     * 查询业主管理
     * 
     * @param ownerId 业主管理主键
     * @return 业主管理
     */
    @Override
    public TbOwner selectTbOwnerByOwnerId(Long ownerId)
    {
        return tbOwnerMapper.selectTbOwnerByOwnerId(ownerId);
    }

    /**
     * 查询业主管理列表
     * 
     * @param tbOwner 业主管理
     * @return 业主管理
     */
    @Override
    public List<TbOwner> selectTbOwnerList(TbOwner tbOwner)
    {
        return tbOwnerMapper.selectTbOwnerList(tbOwner);
    }

    /**
     * 新增业主管理
     * 
     * @param tbOwner 业主管理
     * @return 结果
     */
    @Override
    public int insertTbOwner(TbOwner tbOwner)
    {
        return tbOwnerMapper.insertTbOwner(tbOwner);
    }

    /**
     * 修改业主管理
     * 
     * @param tbOwner 业主管理
     * @return 结果
     */
    @Override
    public int updateTbOwner(TbOwner tbOwner)
    {
        return tbOwnerMapper.updateTbOwner(tbOwner);
    }

    /**
     * 批量删除业主管理
     * 
     * @param ownerIds 需要删除的业主管理主键
     * @return 结果
     */
    @Override
    public int deleteTbOwnerByOwnerIds(Long[] ownerIds)
    {
        return tbOwnerMapper.deleteTbOwnerByOwnerIds(ownerIds);
    }

    /**
     * 删除业主管理信息
     * 
     * @param ownerId 业主管理主键
     * @return 结果
     */
    @Override
    public int deleteTbOwnerByOwnerId(Long ownerId)
    {
        return tbOwnerMapper.deleteTbOwnerByOwnerId(ownerId);
    }

    /**
     * 查询业主列表用于下拉选择
     * 
     * @return 业主列表
     */
    @Override
    public List<Map<String, Object>> selectOwnerListForSelect()
    {
        List<TbOwner> ownerList = tbOwnerMapper.selectTbOwnerList(new TbOwner());
        return ownerList.stream().map(owner -> {
            Map<String, Object> map = new HashMap<>();
            map.put("value", owner.getOwnerId());
            map.put("label", owner.getOwnerName() + "（" + owner.getIdentificationNumber() + "）");
            return map;
        }).collect(Collectors.toList());
    }

    /**
     * 搜索业主列表用于下拉选择
     * 
     * @param query 搜索关键词
     * @return 业主列表
     */
    @Override
    public List<Map<String, Object>> searchOwnersForSelect(String query)
    {
        TbOwner searchOwner = new TbOwner();
        searchOwner.setOwnerName(query);
        searchOwner.setIdentificationNumber(query);
        List<TbOwner> ownerList = tbOwnerMapper.searchOwners(searchOwner);
        return ownerList.stream().map(owner -> {
            Map<String, Object> map = new HashMap<>();
            map.put("value", owner.getOwnerId());
            map.put("label", owner.getOwnerName() + "（" + owner.getIdentificationNumber() + "）");
            return map;
        }).collect(Collectors.toList());
    }
}
